import {
    Controller,
    Get,
    Post,
    HttpStatus,
    Body,
    Query,
    Req,
} from '@nestjs/common';
import { FirstService } from './first.service';

@Controller('/first')
export class FirstController {
    constructor(private readonly firstService: FirstService) {}

    @Get('/test')
    first(@Body('test') body, @Query('_id') query, @Req() req) {
        console.log('body', body);
        console.log('query', query);
        console.log(req.headers);
        return this.firstService.first();
    }
    /**
     *
     * @param body body小括号里如果指定了参数名，就会只解析该参数名，只有一个参数时解析成string，query同理
     * @param query 如果小括号里没有指定参数名，body和query默认都不为空，所以下面的判断会失效，一般body和query不同时用
     */
    @Get('/params')
    params(@Body('test') body, @Query('_id') query, @Req() req) {
        console.log('body', body);
        console.log('query', query);
        console.log(req);

        if (body) {
            return {
                type: 'body',
                params: body,
            };
        }
        if (query) {
            return {
                type: 'query',
                params: query,
            };
        }
        return {};
    }
}
